Refactor MCP client initialization and fix method resolution in _mcp.py#9
Closed
Refactor MCP client initialization and fix method resolution in _mcp.py#9
_mcp.py#9Conversation
Feature: Add MCP client support + generic x402-fetch wrapper
Feature: Add MCP client support + generic x402-fetch wrapper
Feature: Add MCP client support + generic x402-fetch wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements MCP client support and a generic x402-fetch wrapper as requested in #7, adding both synchronous and asynchronous variants with full test coverage.
Changes
New files
src/x402_openai/_http.py(+109 lines)create_x402_session(wallet, ...)— synchronousrequests.Sessionsubclass that intercepts HTTP 402 responses, signs the x402 payment challenge, and retries automaticallycreate_async_x402_session(wallet, ...)— asynchttpx.AsyncClientequivalentsrc/x402_openai/_mcp.py(+331 lines)X402MCPClient— synchronous MCP JSON-RPC 2.0 client with x402 payment handling; supports context-manager usageAsyncX402MCPClient— async version usinghttpx.AsyncClient; supportsasync withresult: null/ non-dict results with explicitValueError(JSON-RPC 2.0 §5)src/x402_openai/_cli.py(+60 lines)create-x402-walletentry-point: generates an EVM keypair, saves to~/.x402/wallet.jsonwith0o600permissionsModified files
src/x402_openai/__init__.py(+20 / -1)X402MCPClient,AsyncX402MCPClient,create_x402_session,create_async_x402_sessionpyproject.toml(+3)create-x402-wallet = "x402_openai._cli:main"as an installed scriptTests
tests/test_http.pytests/test_mcp.pytests/test_transport.pyLocal verification
All 61 tests pass (5 test modules: test_http, test_mcp, test_transport, test_wallet_factory, test_wallets).
Closes #7